package cn.luowb.checkchat.controller;

import cn.luowb.checkchat.common.result.Result;
import cn.luowb.checkchat.common.web.Results;
import cn.luowb.checkchat.dao.entity.PostCollectionDO;
import cn.luowb.checkchat.dto.resp.PostCollectionVO;
import cn.luowb.checkchat.service.PostCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/collections")
public class PostCollectionController {
    @Autowired
    private PostCollectionService postCollectionService;

    @PostMapping("/toggle")
    public Result toggle(@RequestBody PostCollectionDO postCollectionDO) {
        System.out.println("toggle:" + postCollectionDO.getPostId());
        boolean isCollected = postCollectionService.toggle(postCollectionDO.getPostId());
        return Results.success(isCollected);
    }

    /**
     * 获取用户收藏的帖子
     *
     * @param
     * @return
     */
    @GetMapping("/list")
    public Result<PostCollectionVO> getlist(
            @RequestParam(required = false, defaultValue = "1") Integer size,
            @RequestParam(required = false, defaultValue = "0") Long lastId) {
        PostCollectionVO list = postCollectionService.getList(size, lastId);
        return Results.success(list);
    }

}
